#include "StackTab.h"
#include <QPushButton>
#include "../../Utility/XXlogger.h"

StackTab::StackTab(QObject *parent) : QObject(parent){
    connect(&_buttonGroup,SIGNAL(sigSelectionChanged(QStringList,QStringList)),this,SLOT(buttonGroup_onSelectionChanged(QStringList,QStringList)));
    _buttonGroup.setSelectable(true);
    _buttonGroup.setExclusive(true,false);
}

void StackTab::shell(QStackedWidget *stack, QWidget *bar){
    _stackedWidget = stack;
    _buttonGroup.shell(bar);
    _stackedShell.shell(stack);
}
void StackTab::select(const QString &name){
    _buttonGroup.select(name);
    _stackedShell.showWidget(name);
}
QString StackTab::currentSelected(){
    auto list = _buttonGroup.currentSelected();
    return list.isEmpty() ? "" : list.first();
}

void StackTab::buttonGroup_onSelectionChanged(QStringList current, QStringList previous){
    Q_UNUSED(previous);
    if(!_stackedShell.contains(current.first())){
        xxErrStrF(("can not find widget with name:%1.").arg(current.first()));
        return;
    }
    _stackedShell.showWidget(current.first());
    emit sigCurrentTabChanged(current.isEmpty()?"":current.first(),previous.isEmpty()?"":previous.first());
}

